home *** CD-ROM | disk | FTP | other *** search
- /* stripfile.cpp
- *
- * This contains the actual strip code. There are two versions of this
- * file, one for the 68K version, and one for the PPC version
- */
-
- #include "Strip.h"
-
- /************************************************************************/
- /* */
- /* Error Display Code */
- /* */
- /************************************************************************/
-
- /* DisplayAlert
- *
- * Display the alert, given the application name and message
- */
-
- static void DisplayAlert(FSSpec *file, short id, short code)
- {
- unsigned char buffer[256];
- unsigned char codeStr[32];
-
- GetIndString(buffer,128,id);
- if (code) {
- NumToString(code,codeStr);
- ParamText(file->name,buffer,codeStr,NULL);
- } else {
- ParamText(file->name,buffer,NULL,NULL);
- }
- Alert(130,NULL);
- }
-
- /************************************************************************/
- /* */
- /* Main entry point */
- /* */
- /************************************************************************/
-
- /* StripFile
- *
- * Determine if this file is the correct one by type and temperment;
- * if it is, then go ahead and strip the code resources and replace them
- * with one that presents a very simple message.
- */
-
- void StripFile(FSSpec *file)
- {
- FInfo finfo;
- short appRefNum;
- Handle alert,ditl,code;
- short len,off;
- short err;
-
- /*
- * Figure out what the file type is.
- */
-
- if (FHasFSSpec) FSpGetFInfo(file,&finfo);
- else HGetFInfo(file->vRefNum,file->parID,file->name,&finfo);
-
- if (finfo.fdType != 'APPL') {
- DisplayAlert(file,1,0);
- return;
- }
-
- /*
- * Now open this application for modification.
- */
-
- if (FHasFSSpec) appRefNum = FSpOpenResFile(file,fsRdWrPerm);
- else appRefNum = HOpenResFile(file->vRefNum,file->parID,file->name,fsRdWrPerm);
- if (appRefNum == -1) {
- DisplayAlert(file,2,0);
- return;
- }
-
- /*
- * Is there a code fragment resource?
- */
-
- SetResLoad(false);
- code = Get1Resource('cfrg',0);
- SetResLoad(true);
- if (code == NULL) {
- CloseResFile(appRefNum);
- DisplayAlert(file,5,0);
- return;
- } else ReleaseResource(code);
-
- /*
- * Determine if the alert resources that I wish to copy are available
- */
-
- SetResLoad(false);
- code = Get1Resource('CODE',0);
- SetResLoad(true);
- if (code == NULL) {
- CloseResFile(appRefNum);
- DisplayAlert(file,4,0);
- return;
- } else ReleaseResource(code);
-
- SetResLoad(false);
- alert = Get1Resource('ALRT',27309);
- SetResLoad(true);
- if (alert != NULL) {
- ReleaseResource(alert);
- CloseResFile(appRefNum);
- DisplayAlert(file,3,0);
- return;
- }
- SetResLoad(false);
- ditl = Get1Resource('DITL',27309);
- SetResLoad(true);
- if (ditl != NULL) {
- ReleaseResource(ditl);
- CloseResFile(appRefNum);
- DisplayAlert(file,3,0);
- return;
- }
-
- /*
- * Time to do the fixup
- */
-
- len = Count1Resources('CODE');
- for (off = len; off > 0; off--) {
- SetResLoad(false);
- code = Get1IndResource('CODE',off);
- SetResLoad(true);
- SetResAttrs(code,0);
- RemoveResource(code); // Remove from this one
- if (0 != (err = ResError())) {
- CloseResFile(appRefNum);
- DisplayAlert(file,6,err);
- return;
- }
- DisposeHandle(code);
- }
-
- alert = GetResource('ALRT',27309); // Pull it from me
- DetachResource(alert);
- AddResource(alert,'ALRT',27309,"\pAdded by Strip68K");
- WriteResource(alert);
- ReleaseResource(alert);
-
- ditl = GetResource('DITL',27309);
- DetachResource(ditl);
- AddResource(ditl,'DITL',27309,"\pAdded by Strip68K");
- WriteResource(alert);
- ReleaseResource(alert);
-
- code = GetResource('c68K',128);
- DetachResource(code);
- AddResource(code,'CODE',0,"\pAdded by Strip68K");
- WriteResource(code);
- ReleaseResource(code);
-
- code = GetResource('c68K',129);
- DetachResource(code);
- AddResource(code,'CODE',1,"\pAdded by Strip68K");
- WriteResource(code);
- ReleaseResource(code);
-
- UpdateResFile(appRefNum);
- CloseResFile(appRefNum);
- }
-